import pygame, math, sys, random

class Helicopter():
    def __init__(self, maxSpeed, position, screenSize, speed, waitMax = 50):
        self.surface = pygame.image.load("rsc/helicopter1.png")
        self.surface = pygame.transform.scale(self.surface,(100, 100))
        self.rect = self.surface.get_rect()
        self.speed = [0,0]
        self.maxSpeed = speed
        self.place(position)
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.radius = self.rect.width/2
        self.life = 100
        self.living = True
        self.damage = 5
        """
        #Anmimation Variables
        self.waitCount = 0
        self.waitMax = waitMax
        self.frame = 0
        self.maxFrame = len(self.surfaces) - 1
        """

        
    def  __str__(self):
        return "I'm a Helicopter" + str(self.rect.center),
        pass
     
    def place(self, position):
        self.rect.center = position
        #print "I've moved to", position
        
    def move(self):
        self.rect = self.rect.move(self.speed)
        """
        #Animation Code
        if self.waitCount < self.waitMax:
            self.waitCount += 1
        else:
            self.waitCount = 0
            if self.frame < self.maxFrame:
                self.frame += 1
            else:
                self.frame = 0
            self.surface = self.surfaces[self.frame]
        """
    
    def collideWall(self, screenWidth, screenHeight):
        hit = False
        print self.rect.center
        if self.rect.center[0] < 0:
            hit = "W"
            self.rect.center = [screenWidth, self.rect.center[1]]
        elif self.rect.center[0] > screenWidth:
            hit = "E"
            self.rect.center = [0, self.rect.center[1]]
        if self.rect.center[1] < 0:
            if not hit:
                hit = "N"
            else:
                hit = "N" + hit
            self.rect.center = [self.rect.center[0], screenHeight]
        elif self.rect.center[1] > screenHeight:
            if not hit:
                hit = "S"
            else:
                hit = "S" + hit
            self.rect.center = [self.rect.center[0], 0]
        return hit
    
    def direction(self, dir):
        if dir == "up":
            self.speed[1] = -self.maxSpeed
        elif dir == "down":
            self.speed[1] = self.maxSpeed
        elif dir == "right":
            self.speed[0] = self.maxSpeed
        elif dir == "left":
            self.speed[0] = -self.maxSpeed
        
        elif dir == "stop up":
            self.speed[1] = 0
        elif dir == "stop down":
            self.speed[1] = 0
        elif dir == "stop right":
            self.speed[0] = 0
        elif dir == "stop left":
            self.speed[0] = 0
            
    def enemyCollide(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius):  
                    self.living = False
                    other.living = False
                    
    def collideBullet(self, bullet):        
        if (self.rect.right > bullet.rect.left 
            and self.rect.left < bullet.rect.right):
            if (self.rect.bottom > bullet.rect.top and 
                self.rect.top < bullet.rect.bottom):
                if (self.distToPoint(bullet.rect.center)
                    < self.radius + bullet.radius): 
                    self.living = False
                    bullet.living = False
              
    def hurt(self, amount):
        self.life -= amount
        if self.life <= 0:
            self.living = False
                    
                    